﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportCustomerFee.aspx.cs" Inherits="FL.WebUI.ReportList.ReportCustomerFee" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>客户报表打印</title>
    <script src="../Scripts/report/CreateControl.js"></script>
    <script src="../Scripts/report/GRInstall.js"></script>
    <script src="../Scripts/report/GRUtility.js"></script>
    <script src="../Scripts/jquery-2.1.4.min.js"></script>
    <script src="../Scripts/common/jquery.data.js"></script>
    <script type="text/javascript">
        Install_InsertReport();
    </script>
    <script type="text/javascript">
        var Report;

        function window_onload() {
            Report = ReportViewer.Report;
            //定义报表主对象的属性
            Report.Font.Point = 9;//所有字体大小
            Report.DesignPaperWidth = 30;//设计宽度
            Report.Printer.PaperSize = 256;//8是A3纸张，具体请查看api
            Report.Printer.PaperWidth = 30;
            Report.Printer.PaperLength = 15.2;

            Report.DesignPaperLength = 15.2;//纸张高度
            Report.Printer.BottomMargin = 2;
            Report.Printer.LeftMargin = 0.3;
            Report.Printer.RightMargin = 0;
            Report.Printer.TopMargin = 0;
            //通过程序代码定义报表模板
            //<<
            //Report.Clear();


            //Report.DesignPaperWidth = 29;
            //Report.DesignPaperHeight = 15;
            // console.log(Report);
            //Report.DesignPaperOrientation = 1;

            //定义页眉
            DefinePageHeader();

            //定义页脚
            DefinePageFooter();

            //定义报表头
            DefineReportHeader();


            //定义报表尾
            DefineReportFooter();

            //定义明细网格
            DefineDetailGrid();
            //>>

            //如果要检查定义的模板，可以保存到文件，然后用报表设计器打开查看
            Report.SaveToFile("d:\\Program.grf");

            //启动报表运行
            ReportViewer.Start();
        }



        //定义页眉
        function DefinePageHeader() {
            Report.InsertPageHeader();
            Report.PageHeader.Height = 0.58;

            ////插入一个部件框
            //var StaticBox = Report.PageHeader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            //StaticBox.Text = "欢迎访问：www.GridppReport.com，了解最新产品信息";
            //StaticBox.ForeColor = ColorFromRGB(0, 0, 255); //Red = 0, Green = 0, Blue = 255
            //StaticBox.Left = 0;
            //StaticBox.Top = 0;
            //StaticBox.Width = 8.20;
            //StaticBox.Height = 0.58;

            ////插入另一个部件框
            //StaticBox = Report.PageHeader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            //StaticBox.Text = "Grid++Report 示例";
            //StaticBox.Font.Point = 11;
            //StaticBox.Font.Bold = true;
            //StaticBox.Dock = 3; //GRDockStyle.grdsRight 使其锚定到页眉的右端
            //StaticBox.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
            //StaticBox.Width = 6;
        }

        //定义页脚
        function DefinePageFooter() {

        }

        //定义报表头
        function DefineReportHeader() {
            var Reportheader = Report.ReportHeaders.Add();
            Reportheader.RepeatOnPage = true;//表头每页打印
            //Reportheader.Height = 1.38;
            Reportheader.Height = 3.5;
            //插入一个静态文本框,显示报表标题文字
            var StaticBox = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            StaticBox.Text = "深圳市华商联物流报关有限公司 报关费月结单";
            //StaticBox.Center = 1; //GRCenterStyle.grcsHorizontal 使部件框在节中水平方向上居中对齐
            StaticBox.Font.Point = 15;
            StaticBox.Font.Bold = true;
            StaticBox.Top = 1.9;
            StaticBox.Width = 12;
            StaticBox.Left = 8;
            StaticBox.Height = 0.58;

            ////客户名称+简称
            var customername = Reportheader.Controls.Add(1).AsStaticBox; //grcontroltype.grctstaticbox
            customername.Text = "客户：" + '<%=customerName%>' + "  " + '（<%=customerShortName+secondCustomer%>）';
            customername.Left = 0.5;
            customername.Top = 2.7;
            customername.Width = 8.5;
            customername.Height = 0.58;

            ////结算人
            var employeename = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            employeename.Text = "联系人:" + '<%=jsyName%>';
            //StaticBox1.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
            employeename.Left = 11;
            employeename.Top = 2.7;
            employeename.Width = 5.5;
            employeename.Height = 0.58;

            ////结算人联系电话
            var tel = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            tel.Text = "Tel(Fax):" + '<%=jsyTel%>';
            //StaticBox1.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
	        tel.Left = 14.5;
	        tel.Top = 2.7;
	        tel.Width = 5.5;
	        tel.Height = 0.58;

            ////插入对账单号
	        var customerLian = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
	        var tmp_infos = fnGetData("t_customer_fees_tmp", "id=" + '<%=Request["tmpId"]%>');

	        customerLian.Text = tmp_infos.data[0].tmp_name + '<%=billNos%>';
            //StaticBox1.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
            //WordWrap 自动绕行
            customerLian.WordWrap = true;
            customerLian.Left = 20;
            customerLian.Top = 2.1;
            customerLian.Border = 1;
            customerLian.bord = 1;
            //customerLian.BorderStyles = 2;
            //customerLian.BorderStyles = 4;
            customerLian.TextAlign = 34;
            customerLian.Font.Point = 11;
            customerLian.BorderStyles = 15;
            customerLian.PaddingLeft = 1.5;
            customerLian.PaddingRight = 1.5;
            customerLian.PaddingTop = 1.5;
            customerLian.PaddingBottom = 1.5;
            customerLian.Width = 4.2;
            customerLian.Height = 1.3;


            ////第二客户
            var secondCustomer = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            secondCustomer.Text = '<%=customerName%>' + "  " + '（<%=customerShortName+secondCustomer%>）';
            secondCustomer.TextAlign = 33;
            //StaticBox1.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
            secondCustomer.Left = 20;
            secondCustomer.Height = 0.58;
            secondCustomer.Top = 1.6;
            secondCustomer.Width = 7;
            secondCustomer.Height = 0.58;
            ////计费
            var customerLian1 = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            customerLian1.Text = '<%=chargeName%>';
            //StaticBox1.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleRight 使文本对齐到右端
	        customerLian1.Left = 25.5;
	        customerLian1.Width = 5.5;
	        customerLian1.Height = 0.58;
	        customerLian1.Top = 2.7;
	        customerLian1.Width = 5.5;
	        customerLian1.Height = 0.58;


            //插入一个系统变量框,显示页号
	        var PageNoBox = Reportheader.Controls.Add(3).AsSystemVarBox; //GRControlType.grctSystemVarBox
	        PageNoBox.SystemVar = 3; //GRSystemVarType.grsvPageNumber
	        PageNoBox.TextFormat.TextAlign = 34; //GRTextAlign.grtaMiddleRight
	        PageNoBox.Left = 24.38;
	        PageNoBox.Top = 3;
	        PageNoBox.Width = 0.6;
	        PageNoBox.Height = 0.40;

            //插入一个静态文本框,显示页号与总页数中间的分隔斜线字符'/'
	        var StaticBoxXie = Reportheader.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
	        StaticBoxXie.Text = "/";
	        StaticBoxXie.TextFormat.TextAlign = 36; //GRTextAlign.grtaMiddleCenter
	        StaticBoxXie.Left = 24.72;
	        StaticBoxXie.Top = 3;
	        StaticBoxXie.Width = 0.40;
	        StaticBoxXie.Height = 0.40;

            //插入另一个系统变量框,显示页数
	        var PageCountBox = Reportheader.Controls.Add(3).AsSystemVarBox; //GRControlType.grctSystemVarBox
	        PageCountBox.SystemVar = 2; //GRSystemVarType.grsvPageCount
	        PageCountBox.Left = 25.08;
	        PageCountBox.Top = 3;
	        PageCountBox.Width = 1.40;
	        PageCountBox.Height = 0.40;


        }

        function DefineReportFooter() {
        }

        function DefineDetailGrid() {

            var tmpId = '<%=Request["tmpId"]%>';
            var tmp_infos = fnGetData("t_customer_fees_tmp_infos", "tmp_id=" + tmpId, "sort", "IsDesc");
            //var data = [{ fieldName: "OrderID", fieldType: 2, description: "产品名称", width: 2.78 },
            //            { fieldName: "CustomerID", fieldType: 1, description: "", width: 0 },
            //            { fieldName: "CompanyName", fieldType: 1, description: "", width: 0 },
            //            { fieldName: "OrderDate", fieldType: 6, description: "", width: 0 },
            //            { fieldName: "Freight", fieldType: 3, description: "", width: 0 },
            //            { fieldName: "ProductID", fieldType: 2, description: "", width: 0 },
            //            { fieldName: "ProductName", fieldType: 1, description: "", width: 0 },
            //            { fieldName: "UnitPrice", fieldType: 3, description: "单价", width: 1.98 },
            //            { fieldName: "Quantity", fieldType: 2, description: "数量", width: 1.59 },
            //            { fieldName: "Discount", fieldType: 3, description: "折扣", width: 1.80 },
            //            { fieldName: "Amount", fieldType: 3, description: "折扣前金额", width: 2.38 },
            //            { fieldName: "DiscountAmt", fieldType: 3, description: "", width: 0 },
            //            { fieldName: "NetAmount", fieldType: 3, description: "折扣后金额", width: 2.38 }];

            var t = Report.InsertDetailGrid();
            Report.DetailGrid.ColumnTitle.Height = 0.85;
            Report.DetailGrid.ColumnTitle.RepeatStyle = 2;
            Report.DetailGrid.ColumnContent.Height = 0.85;
            //Red = 255, Green = 196, Blue = 196
            // Report.DetailGrid.ColumnContent.AlternatingBackColor = ColorFromRGB(196, 196, 255);
            //Report.DetailGrid.PrintAdaptFitText =true;
            //Report.DetailGrid.FixedWidth = false;
            //定义数据集的各个字段
            var RecordSet = Report.DetailGrid.Recordset;
            for (var i = 0; i < tmp_infos.total; i++) {
                if (tmp_infos.data[i].custom_name == "日期") {
                    var date = RecordSet.AddField(tmp_infos.data[i].custom_name, 6);
                    date.Format = "yyMMdd";
                } else {
                    //if (tmp_infos.data[i].is_count == 1) {
                    //    var total = RecordSet.AddField(tmp_infos.data[i].custom_name, 3);
                    //    total.Format = "0";
                    //} else {
                    //    RecordSet.AddField(tmp_infos.data[i].custom_name, 1);
                        
                    //}
                    var b = RecordSet.AddField(tmp_infos.data[i].custom_name, 1);
                    b.Format = "0";
                }


            }
            
            var margerNames = [];
            //定义列
            //var title1 = Report.DetailGrid.AddColumn("序", "序", "序", 0.6);

            //title1.TitleCell.TextAlign = 34;
            //title1.ContentCell.FreeCell = true;
            //title1.ContentCell.Controls.RemoveAll();
            //var SystemVarBox = title1.ContentCell.Controls.Add(3).AsSystemVarBox;
            //SystemVarBox.Dock = 5;
            //SystemVarBox.TextAlign = 34;
            //SystemVarBox.SystemVar = 4;
            //定义分组
            var Group = Report.DetailGrid.Groups.Add();
            var count_left = 0;//合计距离左侧距离
            for (var j in tmp_infos.data) {
                if (tmp_infos.data[j].custom_name != "") {
                    if (tmp_infos.data[j].is_count == 0) {
                        count_left += parseFloat(tmp_infos.data[j].width);
                    }
                    //tmp_infos.data[j].width == null ? 2 : tmp_infos.data[j].width
                    console.log(tmp_infos.data[j].width=="");
                    var title = Report.DetailGrid.AddColumn(tmp_infos.data[j].custom_name, tmp_infos.data[j].custom_name, tmp_infos.data[j].custom_name, tmp_infos.data[j].width == "" ? 2 : tmp_infos.data[j].width);
                    title.FixedWidth = true;
                    title.TitleCell.TextAlign = 34;
                    title.TitleCell.WordWrap = true;
                    title.ContentCell.WordWrap = true;
                    title.ContentCell.TextAlign = 34;

                    //<<定义双层表头
                    if (tmp_infos.data[j].merge_name != "") {
                        //判断标题是否存在
                        if (margerNames.toString().indexOf(tmp_infos.data[j].merge_name) == -1) {
                            var ColumnTitleCell1 = Report.DetailGrid.AddGroupTitle("column" + j.toString(), tmp_infos.data[j].merge_name);
                            ColumnTitleCell1.TextFormat.TextAlign = 34; //GRTextAlign.grtaMiddleCenter
                            margerNames.push(tmp_infos.data[j].merge_name);
                        }
                        ColumnTitleCell1.EncloseColumn(tmp_infos.data[j].custom_name);
                    }

                    if (tmp_infos.data[j].is_count == 1) {//有合计的
                        var summary = Group.Footer.Controls.Add(5).AsSummaryBox; //GRControlType.grctSummaryBox
                        summary.SummaryFun = 1; //GRSummaryFun.grsfSum
                        summary.TextAlign = 34;
                        summary.Format = "0.00";
                        summary.Width = tmp_infos.data[j].width == "" ? 2 : tmp_infos.data[j].width;
                        summary.DataField = tmp_infos.data[j].custom_name;//通过对齐到列确定部件框的左边位置与宽度
                        summary.AlignColumn = tmp_infos.data[j].custom_name;
                        summary.BorderStyles = 13;
                        summary.Height = 0.85;
                    }
                }
            }

            Group.Header.Height = 0;
            //Group.ByFields = "序";
            Group.Footer.Height = 0.85;
            var count = Group.Footer.Controls.Add(1).AsStaticBox; //GRControlType.grctStaticBox
            count.Text = "合计";
            
            count.Left = 0.40;
            count.TextAlign = 34;
            count.Left = count_left - 1.5;
            count.Width = 1;
            count.Height = 0.85;




        }
    </script>
    <style type="text/css">
        html, body {
            margin: 0;
            height: 100%;
        }
    </style>
</head>
<body style="margin: 0" onload="return window_onload()">
    <script type="text/javascript">
        var tmpId = '<%=Request["tmpId"]%>';
        var tmpType = '<%=Request["tmpType"]%>';
        var id = '<%=Request["id"]%>';
        var billNo = "<%=Request["billNo"]%>";
        var printIds = '<%=printIds%>';
        var dataUrl = "id=" + id + "&billNo=" + billNo + "&tmpId=" + tmpId + "&tmpType=" + tmpType + "&printIds=" + printIds;
        CreatePrintViewerEx("100%", "100%", "", encodeURI("../../Report/printCustomer?" + dataUrl), false, "");
    </script>
</body>
</html>
